package com.aiowang.springboot.dynamic.activemq.example.jms;



import com.aiowang.springboot.dynamic.activemq.utils.DynamicActiveMQUtils;
import org.apache.activemq.Message;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

import javax.jms.JMSException;

@Component
class ActiveMQClient {

   /**
     * 订阅消息，containerFactory的值为配置文件中spring.activemq.dynamic.xxx.topic-factory的值
    *
     * @param msg 接收消息内容，需要使用DynamicActiveMQUtils.getTextMessag格式化消息
     * @throws JMSException 异常
     * @throws Exception 异常
    */
    @JmsListener(destination = "Test.CustomActiveMq.topic", containerFactory = "customTopic")
    public void customActiveMqClientTopic1(final Message msg) throws JMSException, Exception{
        System.out.println("customActiveMqClientTopic1:customTopic---Test.CustomActiveMq.topic消息:" + DynamicActiveMQUtils.getTextMessage(msg));
        DynamicActiveMQUtils.sendQueue("Test.CustomActiveMq.queue", DynamicActiveMQUtils.getTextMessage(msg));
    }

    /**
     * 订阅消息，containerFactory的值为配置文件中spring.activemq.dynamic.xxx.queue-factory的值
     *
     * @param msg 接收消息内容，需要使用DynamicActiveMQUtils.getTextMessag格式化消息
     * @throws JMSException 异常
     * @throws Exception    异常
     */
     @JmsListener(destination = "Test.CustomActiveMq.queue", containerFactory = "customQueue")
     public void customActiveMqClientQueue1(final Message msg) throws JMSException, Exception{
        System.out.printf("customActiveMqClientQueue1: customQueue---Test.CustomActiveMq.queue消息：%s。", DynamicActiveMQUtils.getTextMessage(msg));
     }

    /**
     * 订阅消息，containerFactory的值为配置文件中spring.activemq.dynamic.xxx.topic-factory的值
     *
     * @param msg 接收消息内容，需要使用DynamicActiveMQUtils.getTextMessag格式化消息
     * @throws JMSException 异常
     * @throws Exception    异常
     */
    @JmsListener(destination = "Test.ProActiveMq.topic", containerFactory = "proTopic")
    public void proActiveMqClientTopic1(final Message msg) throws JMSException, Exception{
        System.out.printf("proActiveMqClientTopic1: proTopic---Test.ProActiveMq.topic消息：%s。", DynamicActiveMQUtils.getTextMessage(msg));
    }

    /**
     * 订阅消息，containerFactory的值为配置文件中spring.activemq.dynamic.xxx.queue-factory的值
     *
     * @param msg 接收消息内容，需要使用DynamicActiveMQUtils.getTextMessag格式化消息
     * @throws JMSException 异常
     * @throws Exception    异常
     */
    @JmsListener(destination = "Test.ProActiveMq.queue", containerFactory = "proQueue")
    public void proActiveMqClientQueue1(final Message msg) throws JMSException, Exception{
        System.out.printf("proActiveMqClientQueue1: proQueue---Test.ProActiveMq.queue消息：%s。", DynamicActiveMQUtils.getTextMessage(msg));
    }

}